<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <title>入库管理</title>
    <link rel="stylesheet" type="text/css" href="./css/main.css" />
    <link rel="stylesheet" type="text/css" href="./layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="./css/layuiAdminTheme.css" />
    <style type="text/css">
        .organizeName,
        .operation span:first-of-type {
            color: #1990FF;
        }

        .operation span:last-of-type {
            color: #f5222d;
        }

        .pageNav {
            margin: 0 auto;
            width: fit-content;
        }

        .pageNav a,
        .operation span {
            cursor: pointer;
            display: inline-block;
        }

        cite {
            cursor: default;
        }

        .twoRow {
            text-overflow: -o-ellipsis-lastline;
            overflow: hidden;
            word-break: break-all;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .layui-table tr td:nth-of-type(3) {
            min-width: 5em;
        }

        td
        {
            white-space: nowrap;
            text-align: center;
        }

        label{
            width: auto;
        }
    </style>
</head>
<body>
<script src="./js/main.js" charset="utf-8"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/jquery" charset="utf-8"></script>-->
<script src="./layui/layui.js" charset="utf-8"></script>
<script src="./js/jQuery.main.js"></script>
<script src="./js/xm-select.js"></script>

<form class="layui-form" action="" lay-filter="data">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" style="width: auto !important;">搜索：</label>
            <input type="text" name="inNum" class="layui-input" style="width: 14em;" placeholder="入库单号" value="">
        </div>
        <div class="layui-inline">
            <select name="deptName" id="deptName" lay-verify="required" lay-filter="deptName">
            </select>
        </div>
        <div class="layui-inline">
            <select name="pinName" id="pinName" lay-filter="pinName" lay-search="">
                <option value="">请选择品名...</option>
            </select>
        </div>
        <div class="layui-inline">
            <input type="text" name="machineNum" class="layui-input" placeholder="所属机台">
        </div>
        <div class="layui-inline">
            <input type="text" name="displayLength" class="layui-input" style="display: none;" placeholder="每页页数" value="10">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="searchBtn">查询入库单</button>
        </div>

        <div class="layui-inline" style="float: right">
            <button id="outStorageBtn" type="button" class="layui-btn layui-bg-cyan" lay-filter="outStorageBtn"><i class="layui-icon">&#xe654;</i>  新增入库</button>
        </div>
    </div>
</form>

<table class="layui-table">
    <thead>
    <tr>
        <!--          <th><input type="checkbox" id="select" onclick="selectAll()" /></th>-->
        <th style="text-align: center">入库单号</th>
        <th style="text-align: center">产品名</th>
        <th style="text-align: center">所属机台</th>
        <th style="text-align: center">初始数量</th>
        <th style="text-align: center">当前数量</th>
        <th style="text-align: center">所属部门</th>
        <th style="text-align: center">创建时间</th>
        <th style="text-align: center">操作</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>
<div style="display: flex;">
    <!--      <button type="button" class="layui-btn layui-btn-xs" style="background: #F5222D;" onclick="deleteProject()">批量删除</button>-->
    <div style="flex: 1">
        <div class="pageNav">
          <span class="layui-breadcrumb" lay-separator="-">
            <a class="fristPage">首页</a>
            <a class="lastPage">上一页</a>
            <a><cite>第<span id="page"></span>页</cite></a>
            <a class="nextPage">下一页</a>
            <a class="endPage">尾页</a>
          </span>
        </div>
    </div>
</div>

<div id="processInfo"  class="site-text" style="margin: 5%; display: none"></div>


<script type="text/javascript">
    var displayStart = 1;
    var endPage = null;
    var layer = layui.layer;
    var laydate = null;
    var form = null;
    var list = null;

    layui.use(['form', 'element', 'laydate'], function() {
        form = layui.form;
        laydate = layui.laydate;
        $.ajax({
            url: url + '/sys-dept/listDept',
            method: 'POST',
            async : false,
            contentType: 'application/json',
            success: function(res) {
                //显示前先判断是否为管理员
                $.ajax({
                    url: '/sys-user/getAdmin/'+sessionStorage.getItem('userId'),
                    method: 'GET',
                    async : false,
                    contentType: 'application/json',
                    success: function (res) {
                        if (res.code===200){
                            isAd=1;
                        }
                        else if (res.code===400){
                            isAd=0;
                            thisDept=res.data.dept;
                        }
                    }
                })
                //按照是否为管理员显示下拉框
                if (res.code == 200) {
                    for (var i = 0; i < res.data.length; i++) {
                        if(isAd===1){
                            $("#deptName").append("<option value='" + res.data[i].id + "'>" + res.data[i].dept +"</option>");
                        }else if (isAd===0&&res.data[i].dept===thisDept){
                            $("#deptName").append("<option selected='selected' value='" + res.data[i].id + "'>" + res.data[i].dept +"</option>").attr('disabled','disabled');
                        }
                    }
                    form.render('select');
                }
            }
        })
        //品名下拉框
        $.ajax({
            url: url + '/pin-library/listPinName',
            method: 'POST',
            async : false,
            contentType: 'application/json',
            data: JSON.stringify({
                userId:"",
                deptId: $('#deptName').val()
            }),
            success: function(res) {
                if (res.code == 200) {
                    for (var i = 0; i < res.data.length; i++) {
                        $("#pinName").append("<option value='" + res.data[i].id + "'>" + res.data[i].pinName +"</option>");
                    }
                }
            }
        })

        search(1);

        form.on('submit(searchBtn)', function() {
            search(1);
            return false;
        });
        $('.fristPage').click(function() {
            search(1);
            return false;
        });
        $('.lastPage').click(function() {
            search((displayStart > 1 ? displayStart - 1 : 1));
            return false;
        });
        $('.nextPage').click(function() {
            search((displayStart < endPage ? displayStart + 1 : endPage));
            return false;
        });
        $('.endPage').click(function() {
            search(endPage);
            return false;
        })

        //下拉框二级联动---点击部门下拉框
        form.on('select(deptName)', function(data) {
            $("#pinName").empty()
            //品名下拉框
            $.ajax({
                url: url + '/pin-library/listPinName',
                method: 'POST',
                async : false,
                contentType: 'application/json',
                data: JSON.stringify({
                    userId:"",
                    deptId: $('#deptName').val()
                }),
                success: function(res) {
                    $("#pinName").append("<option value=''>请选择品名....</option>");
                    if (res.code == 200) {
                        for (var i = 0; i < res.data.length; i++) {
                            $("#pinName").append("<option value='" + res.data[i].id + "'>" + res.data[i].pinName +"</option>");
                        }
                    }
                }
            })
            form.render('select');
        });
    })


    function listInfo(index) {
        layer.msg(index)
    }

    function outStorage(index) {
        layer.msg(index)
    }

    $('#outStorageBtn').click(function () {
        layer.msg("success")
    })

    function search(index) {
        if (!index) var index = displayStart;
        var data = form.val('data');
        data.displayStart = index;
        data.userId=sessionStorage.getItem('userId');
        data.pinId=$('#pinName').val();
        data.deptId=$('#deptName').val();
        data.inNum=sessionStorage.getItem('userId');
        data.machineNum=sessionStorage.getItem('userId');
        $.ajax({
            url: url + '/in-storage/listInStorage',
            method: 'POST',
            contentType: 'application/json',
            data: JSON.stringify(data),
            success: function(res) {
                $('tbody').empty();
                displayStart = res.data.current;
                endPage = res.data.pages;
                list = res.data.records;
                for (var i = 0; i < res.data.records.length; i++) {
                    $('tbody').append(
                        "<tr>" +
                        "<td class='organizeName'>" + res.data.records[i].inNum + "</td>" +
                        "<td class='organizeName'>" + res.data.records[i].pinName+ "</td>" +
                        "<td class='organizeName'>" + res.data.records[i].machineNum+ "</td>" +
                        "<td class='organizeName'>" + res.data.records[i].totalAmounts+ "</td>" +
                        "<td class='organizeName'>" + res.data.records[i].nowAmounts+ "</td>" +
                        "<td>" + res.data.records[i].deptName + "</td>" +
                        "<td>" + res.data.records[i].createTime.replace('T',' ') + "</td>" +
                        "<td><button type='button' class='layui-btn layui-btn-warm layui-btn-sm' onclick='listInfo(\"" + res.data.records[i].inNum + "\")'>详情</button>" +
                        "<button type='button' class='layui-btn layui-btn-normal layui-btn-sm' onclick='outStorage(\"" + res.data.records[i].inNum + "\")'>出库</button></td>" +
                        "</tr>"
                    );
                }
                $('#page').html(displayStart)
            }
        })
    }
</script>
</body>
</html>
